<?php

namespace app\home\controller;

use app\common\controller\Home;
use think\Cache;

class Mapi extends Home
{
	public function index()
	{
		return 'react';
	}

	// 各种配置参数
	public function config()
	{
		$array = array();
		$param = zanpiancms_param_url();
		$tag = $param['tag'];
		$config = $GLOBALS['config'];
		$menu = F('_data/listtree');
		foreach ($menu as $i => $val) {
			$listMenu[$i]['id'] = $val['list_id'];
			$listMenu[$i]['title'] = $val['list_name'];
			$listMenu[$i]['name'] = $val['list_dir'];
			if ($val['son']) {
				foreach ($val['son'] as $k => $v) {
					$listMenu[$i]['son'][$k]['id'] = $v['list_id'];
					$listMenu[$i]['son'][$k]['title'] = $v['list_name'];
					$listMenu[$i]['son'][$k]['name'] = $v['list_dir'];
				}
			}
		}
		if ($tag == 'menu') {
			$p = $param['p'] - 1;
			$array = $listMenu[$p ? $p : 7];
		} else {
			$k = 0;
			$list = array();
			$data = model('mcat')->listMcid();
			array_multisort(array_column($data, 'm_order'), SORT_ASC, $data); // 按order排序
			foreach ($data as $i => $val) {
				if ($val['m_list_id'] == 3) {
					$list[$k]['id'] = $val['m_cid'];
					$list[$k]['title'] = $val['m_name'];
					// $list[$k]['name'] = $val['m_ename'];
					// $list[$k]['order'] = $val['m_order'];
					$k = $k + 1;
				}
			}
			$array['mcid'] = $list;
			$array['menu'] = $listMenu[2];
			$array['area'] = explode(',', $config['video']['video_area']);
			$array['year'] = explode(',', $config['video']['video_year']);
			$array['letter'] = (range(A, Z));
		}
		return json(['data' => $array]);
	}

	// 轮播图 循环查询相关标签幻灯片
	function slide()
	{
		$data = zanpian_mysql_slide('limit:6;nocid:-1;order:slide_oid asc');
		$list = array();
		if ($data) {
			foreach ($data as $i => $val) {
				$list[$i]['title'] = $val['slide_name'];
				$list[$i]['pic'] = $val['slide_bigpic'];
				$list[$i]['url'] = $val['slide_url'];
			}
			return json(['data' => $list]);
		} else {
			return json(['data' => array()]);
		}
	}

	/**
	 * 视频详情接口
	 * @param id 视频ID
	 * @param pinyin 视频拼音
	 */
	public function Detail()
	{
		$param = zanpiancms_param_url();
		$vid = $param['id'];
		$array_detail = $this->get_cache_detail($param);
		if (!empty($vid)) {
			$this->set_hits($vid);
		}
		$list = array();
		if ($array_detail) {
			$show = $array_detail['show'];
			$read = $array_detail['read'];
			$list['listId'] = $show['list_id'];
			$list['listName'] = $show['list_name'];
			$list['listPid'] = $show['list_pid'];
			$list['listNameBig'] = getlistname($show['list_pid'], 'list_name');
			$list['id'] = $read['vod_id'];
			$list['cid'] = $read['vod_cid'];
			$list['title'] = $read['vod_name'];
			$list['aliases'] = $read['vod_aliases'];
			$list['keywords'] = $read['vod_keywords'];
			$list['area'] = $read['vod_area'];
			$list['year'] = $read['vod_year'];
			$list['mcid'] = mcat_json($read['vod_mcid']);
			$list['time'] = time_format($read['vod_addtime'], 'Y-m-d H:i:s', 1);
			$list['updateDate'] = date('Y-m-d H:i:s', $read['vod_addtime']);
			$list['language'] = $read['vod_language'];
			if (!empty($read['vod_original'])) {
				$list['original'] = get_star_json($read['vod_original']);
			}
			if (!empty($read['vod_actor'])) {
				$list['actor'] = get_star_json($read['vod_actor']);
			}
			if (!empty($read['vod_director'])) {
				$list['director'] = get_star_json($read['vod_director']);
			}
			$list['total'] = empty($read['vod_total']) ? 0 : (int) $read['vod_total'];
			$list['gold'] = $read['vod_gold'];
			$list['filmtime'] = empty($read['vod_filmtime']) ? '' : date('Y-m-d', $read['vod_filmtime']);
			$list['company'] = $read['vod_company'];
			$list['website'] = $read['vod_website'];
			$list['tvcont'] = $read['vod_tvcont'];
			$list['repair'] = $read['vod_repair'];
			$list['repairtitle'] = $read['vod_repairtitle'];
			$list['pan'] = $read['vod_pan'];
			$list['pantitle'] = $read['vod_pantitle'];
			$list['letters'] = $read['vod_letters'];
			$list['hits'] = $read['vod_hits'];
			$list['content'] = preg_replace("/<(.*?)>/", '', $read['vod_content']);
			$list['pic'] = zanpian_img_url($read['vod_pic']);
			if (is_numeric($read['vod_continu'])) {
				if ($read['vod_continu'] > 0) {
					$read['vod_continu'] = '连载至' . $read['vod_continu'] . '话';
				} else {
					$read['vod_continu'] = '完结';
				}
			}
			$list['status'] = $read['vod_continu'];
			$list['storyId'] = $read['story_id'];
			$list['actorId'] = $read['actor_id'];
			$list['copyright'] = $read['vod_reurl'];
			$list['jump'] = $read['vod_jumpurl'];
			$newsText = zanpian_mysql_topic('cid: 214,215,216,217,218,219,220,223;sid: 1;tsid: 2;did:' . $vid . ';limit:100;order:news_addtime desc;');
			$newsPic = zanpian_mysql_topic('cid: 211,206,205,207,208,209,212,213,221,222;sid: 1;tsid: 2;did:' . $vid . ';limit:12;order:news_addtime desc;');
			$story = zanpian_mysql_part('vid:' . $vid . ';limit: 3;order: part_id desc');
			$role = zanpian_mysql_role('vid:' . $vid . ';limit:10');
			$lines = zanpian_mysql_lines('vid:' . $vid . ';limit:10');
			$music = zanpian_mysql_music('vid:' . $vid . ';limit:10');
			if ($newsText) {
				$list['newsTextlist'] = $this->format_newslist($newsText, 1);
			}
			if ($newsPic) {
				$list['newsPiclist'] = $this->format_newslist($newsPic);
			}
			if ($story) {
				$list['storylist'] = $this->format_part($story);
			}
			if ($role) {
				$list['role'] = $this->format_rolelist($role);
			}
			if ($lines) {
				$list['lines'] = $lines;
			}
			if ($music) {
				$list['music'] = $music;
			}
			return json(['data' => $list]);
		} else {
			return json(['data' => array()]);
		}
	}

	// 弹出信息层
	public function pop()
	{
		$param = zanpiancms_param_url();
		$array_detail = $this->get_cache_detail($param);
		$list = array();
		if ($array_detail) {
			$show = $array_detail['show'];
			$read = $array_detail['read'];
			$list['id'] = $read['vod_id'];
			$list['cid'] = $read['vod_cid'];
			$list['name'] = $read['vod_name'];
			$list['year'] = $read['vod_year'];
			$list['mcid'] = get_mcat_url($read['vod_mcid'], $read['vod_cid']);
			$areaurl = zanpian_type_url('home/vod/type', array('id' => $read['vod_cid'], 'dir' => getlistname($read['vod_cid'], 'list_dir'), 'mcid' => "", 'area' => urlencode($read['vod_area']), 'year' => "", 'letter' => "", 'order' => ""));
			$list['area'] = "<a target='_blank' href='" . $areaurl . "'>" . $read['vod_area'] . "</a>";
			$list['list_name'] = $show['list_name'];
			$list['list_url'] = zanpian_show_url($read['vod_cid']);
			$list['time'] = zanpian_from_time($read['vod_addtime']);
			if (!empty($read['vod_actor'])) {
				$list['actor'] = get_star_json($read['vod_actor']);
			}
			if (!empty($read['vod_director'])) {
				$list['director'] = get_star_json($read['vod_director']);
			}
			$list['gold'] = $read['vod_gold'];
			$list['content'] = msubstr($read['vod_content'], 0, 120, h);
			$list['url'] = zanpian_data_url('home/vod/read', array('id' => $read['vod_id'], 'pinyin' => $read['vod_letters'], 'cid' => $read['vod_cid'], 'dir' => getlistname($read['vod_cid'], 'list_dir'), 'jumpurl' => $read['vod_jumpurl']));
			return json(['data' => $list]);
		} else {
			return json(['data' => array()]);
		}
	}

	// 联想搜索
	public function s()
	{
		$Url = zanpiancms_param_url();
		$data = zanpian_mysql_vod('wd:' . $Url['wd'] . ';limit: 10;order:vod_addtime desc;');
		$list = array();
		if ($data) {
			foreach ($data as $key => $val) {
				$list['data'][$key]['id'] = $val['vod_id'];
				$list['data'][$key]['name'] = $val['vod_name'];
				if (is_numeric($val['vod_continu'])) {
					if ($val['vod_continu'] > 0) {
						$val['vod_continu'] = '连载至' . $val['vod_continu'] . '话';
					} else {
						$val['vod_continu'] = '完结';
					}
				} else {
					$val['vod_continu'] = $val['vod_title'];
				}
				$list['data'][$key]['status'] = $val['vod_continu'];
				$list['data'][$key]['url'] = zanpian_read_url('home/vod/read', $val);
			}
			return json(['data' => $list['data']]);
		} else {
			return json(['data' => array()]);
		}
	}

	// 获取播放数据全部JSON
	public function play()
	{
		$Url = zanpiancms_param_url();
		$array_detail = $this->get_cache_detail($Url);
		$pid = $Url['pid'] ? $Url['pid'] : 1;
		$vid = $Url['id'];
		$json = json(['data' => array()]);
		$authcode = new \com\Code();
		$auth = md5('plain-' . md5(date('Y-m-d-H') . $vid . '_' . $pid));  // 加密密钥
		$list = array();
		if (!empty($array_detail)) {
			$array_detail = $this->Lable_Vod_Play(array('id' => $vid, 'sid' => 1, 'pid' => $pid), $array_detail);
			$data = playlist_json($array_detail["read"]["vod_play_list"]);
			if (!empty($Url['pid'])) {
				$read = $array_detail["read"];
				$show = $array_detail["show"];
				$now = $pid - 1;
				$list['id'] = $read['vod_id'];
				$list['title'] = $read['vod_name'];
				$list['listName'] = $show['list_name'];
				$list['listNameBig'] = getlistname($show['list_pid'], 'list_name');
				$list['listId'] = $show['list_id'];
				$list['listIdBig'] = $show['list_pid'];
				$list['subTitle'] = $data[0]['playurls'][$now][0];
				$list['actor'] = $read['vod_actor'];
				$list['storyId'] = $read['story_id'];
				$list['actorId'] = $read['actor_id'];
				$list['pic'] = zanpian_img_url($read['vod_pic']);
				$list['copyright'] = $read['vod_reurl'];
				$list['up'] = $read['vod_up'];
				$list['down'] = $read['vod_down'];
				$list['count'] = $read['play_count'];
				$list['mcid'] = mcat_json($read['vod_mcid']);
				$list['pan'] = $read['vod_pan'];
				$list['gold'] = $read['vod_gold'];
				$list['year'] = $read['vod_year'];
				$list['tvcont'] = $read['vod_tvcont'];
				if (is_numeric($read['vod_continu'])) {
					if ($read['vod_continu'] > 0) {
						$read['vod_continu'] = '连载至' . $read['vod_continu'] . '话';
					} else {
						$read['vod_continu'] = '完结';
					}
				}
				$list['status'] = $read['vod_continu'];
				$list['key'] = $auth;
				if ($pid - 1 > 0) {
					$list['prev'] = $pid - 1;
				}
				if ($pid + 1 <= $read['play_count']) {
					$list['next'] = $pid + 1;
				}
				$i = 0;
				if (is_array($data) && $data) {
					foreach ($data as $key => $val) {
						if ($val['playurls'][$now][1]) {
							$list['list'][$i]['playName'] = $val['playname'];
							$list['list'][$i]['playTitle'] = $val['playtitle'];
							$list['list'][$i]['title'] = $val['playurls'][$now][0];
							$list['list'][$i]['vid'] = base64_encode($authcode->authcode($val['playurls'][$now][1], "ENCODE", $auth, 0));
							if ($val['playurls'][$now][2]) {
								$list['list'][$i]['pic'] = $val['playurls'][$now][2];
							}
							if ($val['playurls'][$now][3]) {
								$list['list'][$i]['isVip'] = $val['playurls'][$now][3];
							}
							$i = $i + 1;
						}
					}
				}
			} else {
				if (is_array($data) && $data) {
					foreach ($data as $key => $val) {
						if ($val['playname'] === 'other') {
							$other = $data[$key];
						}
					}
					$list['playName'] = $data[0]['playname'];
					$list['playTitle'] = $data[0]['playtitle'];
					$list['key'] = $auth;
					if (is_array($data[0]['playurls']) && $data[0]['playurls']) {
						foreach ($data[0]['playurls'] as $key => $val) {
							$list['list'][$key]['title'] = $val[0];
							$list['list'][$key]['episode'] = $val[6];
							if (!empty($other)) {
								$list['list'][$key]['vid'] = base64_encode($authcode->authcode($other['playurls'][$key][1], "ENCODE", $auth, 0));
							} else {
								$list['list'][$key]['vid'] = base64_encode($authcode->authcode($val[1], "ENCODE", $auth, 0));
							}
						}
					}
				} else {
					$list = array();
				}
			}
			$json = json(['data' => $list]);
		}
		return $json;
	}

	/**
	 * 列表，列表筛选，搜索页API接口
	 * 
	 * @param id 视频分类ID
	 * @param mcid 视频小分类ID
	 * @param area 地区
	 * @param year 年份
	 * @param letter 视频首字母
	 * @param order 排序 默认：addtime 按最新 2. hits 总排行 3.hits_week 周排行 4.hits_day 日排行 5.hits_month 月排行
	 * @param lz 1.连载 2 完结
	 * @param language 语言 日语 国语等
	 * @param day 按天获取数据
	 * @param wd 按关键词搜索，标题、别名、拼音、声优、tag
	 * @return json
	 * @param react 1 为追番周期表，空为正常列表
	 */
	public function list()
	{
		$Url = zanpiancms_param_url();
		if ($Url['dir']) {
			$Url['id'] = getlist($Url['dir'], 'list_dir', 'list_id');
			$Url['dir'] = getlist($Url['id'], 'list_id', 'list_dir');
		} else {
			$Url['dir'] = getlist($Url['id'], 'list_id', 'list_dir');
		}
		$Url['limit'] = $Url['limit'] ? $Url['limit'] : 10;
		$data = list_search(F('_data/list'), 'list_id=' . $Url['id']);
		if ($data && $data[0]['list_sid'] == 1) {
			$ajax_list = zanpian_mysql_vod('mcid:' . $Url['mcid'] . ';cid:' . $Url['id'] . ';ids:' . $Url['ids'] . ';year:' . $Url['year'] . ';actor:' . $Url['actor'] . ';lz:' . $Url['lz'] . ';not:' . $Url['not'] . ';letter:' . $Url['letter'] . ';area:' . $Url['area'] . ';language:' . $Url['language'] . ';day:' . $Url['day'] . ';wd:' . $Url['wd'] . ';limit:' . $Url['limit'] . ';page:true;p:' . $Url['p'] . ';order:vod_' . $Url['order'] . ' desc;');
			if ($Url['limit'] == 1000) {
				return $this->format_data($ajax_list, 0, $Url['limit']);
			} else {
				return $this->format_data($ajax_list, $Url['p'], 0, $Url['order']);
			}
		}
	}

	// 关联视频新闻列表
	public function vodnewslist()
	{
		$param = zanpiancms_param_url();
		$param['limit'] = $param['limit'] ? $param['limit'] : 10;
		$list = zanpian_mysql_topic('did: '. $param['id'] .';sid:1;tsid:2;page:true;limit:'. $param['limit'] .';p: '. $param['p'] .'');
		return $this->f_newslist($list, $param['p']);
	}

	// 月份追番表
	public function month()
	{
		$Url = zanpiancms_param_url();
		$month = input('month/d', date('Ym')) . '01';
		$lastday = date('Y-m-d', strtotime("$month +1 month -1 day"));
		$firstday = date("Ym01", strtotime($month));
		if ($Url['dir']) {
			$Url['id'] = getlist($Url['dir'], 'list_dir', 'list_id');
			$Url['dir'] = getlist($Url['id'], 'list_id', 'list_dir');
		} else {
			$Url['dir'] = getlist($Url['id'], 'list_id', 'list_dir');
		}
		$List = list_search(F('_data/list'), 'list_id=' . $Url['id']);
		if ($List && $List[0]['list_sid'] == 1) {
			$ajax_list = zanpian_mysql_vod('cid:' . $Url['id'] . ';limit:150;order:vod_addtime desc;tj:vod_filmtime|between|' . strtotime($firstday) . ',' . strtotime($lastday) . '');
			return $this->format_data($ajax_list);
		}
	}

	public function storylist()
	{
		$Url = zanpiancms_param_url();
		if ($Url['dir']) {
			$Url['id'] = getlist($Url['dir'], 'list_dir', 'list_id');
			$Url['dir'] = getlist($Url['id'], 'list_id', 'list_dir');
		} else {
			$Url['dir'] = getlist($Url['id'], 'list_id', 'list_dir');
		}
		$Url['limit'] = $Url['limit'] ? $Url['limit'] : 10;
		$data = list_search(F('_data/list'), 'list_id=' . $Url['id']);
		$list = array();
		if ($data && $data[0]['list_sid'] == 4) {
			$ajax_list = zanpian_mysql_story('ids:' . $Url['ids'] . ';cid:' . $Url['id'] . ';vcid:' . $Url['vcid'] . ';vid:' . $Url['vid'] . ';name:' . $Url['name'] . ';tj:' . $Url['tj'] . ';stars:' . $Url['stars'] . ';day:' . $Url['day'] . ';lz:' . $Url['lz'] . ';hits:' . $Url['hits'] . ';prty:' . $Url['prty'] . ';limit:' . $Url['limit'] . ';page:true;p:' . $Url['p'] . ';order:story_' . $Url['order'] . ' desc;');
			if ($ajax_list) {
				foreach ($ajax_list as $i => $val) {
					$list['data'][$i]['sid'] = $val['story_id'];
					$list['data'][$i]['scid'] = $val['story_cid'];
					$list['data'][$i]['stitle'] = $val['story_name'];
					$list['data'][$i]['id'] = $val['vod_id'];
					$list['data'][$i]['title'] = $val['vod_name'];
					$list['data'][$i]['name'] = getlistname($val['story_cid'], 'list_name');
					$list['data'][$i]['cid'] = $val['vod_cid'];
					$list['data'][$i]['addtime'] = date('Y-m-d H:i:s', $val['story_addtime']);
					if ($val['story_continu'] > 0) {
						$val['story_continu'] = (int) $val['story_continu'];
					} else {
						$val['story_continu'] = '完结';
					}
					$list['data'][$i]['continu'] = $val['story_continu'];
					$list['data'][$i]['pic'] = zanpian_img_url($val['vod_pic']);
				}
				$list['limit'] = (int) $ajax_list->listRows();
				$list['current'] = $ajax_list->currentPage();
				$list['count'] = $ajax_list->lastPage();
				$list['total'] = $ajax_list->total();
			} else {
				$list['limit'] = $Url['limit'];
				$list['current'] = 1;
				$list['total'] = 0;
				$list['count'] = 0;
				$list['data'] = array();
			}
			return json($list);
		}
	}

	public function newsList()
	{
		$Url = zanpiancms_param_url();
		if ($Url['dir']) {
			$Url['id'] = getlist($Url['dir'], 'list_dir', 'list_id');
			$Url['dir'] = getlist($Url['id'], 'list_id', 'list_dir');
		} else {
			$Url['dir'] = getlist($Url['id'], 'list_id', 'list_dir');
		}
		$data = list_search(F('_data/list'), 'list_id=' . $Url['id']);
		if ($data && $data[0]['list_sid'] == 2) {
			$ajax_list = zanpian_mysql_news('cid:' . $Url['id'] . ';letter:' . $Url['letter'] . ';news:' . $Url['news'] . ';did:' . $Url['did'] . ';day:' . $Url['day'] . ';wd:' . $Url['wd'] . ';name:' . $Url['name'] . ';limit:' . $Url['limit'] . ';page:true;p:' . $Url['p'] . ';order:news_' . $Url['order'] . ' desc;');
			return $this->f_newslist($ajax_list, $Url['p']);
		}
	}
	public function newsDetail()
	{
		$Url = zanpiancms_param_url();
		$nid = $Url['id'];
		if (!empty($nid)) {
			$this->set_hits($nid, 2);
		}
		$array_detail = $this->get_cache_news($Url);
		$Url['page'] = !empty($Url['p']) ? $Url['p'] : 1;
		$detail = $array_detail;
		$list = array();
		if ($detail) {
			$read = $detail['read'];
			$list['id'] = $read['news_id'];
			$list['cid'] = $read['news_cid'];
			$list['name'] = getlistname($read['news_cid'], 'list_name');
			$list['title'] = $read['news_name'];
			if ($read['news_keywords']) {
				$list['tag'] = explode(',', $read['news_keywords']);
				$list['keywords'] = $read['news_keywords'];
			}
			if ($read['news_tag']) {
				$list['tag'] = explode(',', $read['news_tag']);
				$list['keywords'] = $read['news_tag'];
			}
			$list['remark'] = $read['news_remark'];
			if (!empty($read['news_pic'])) {
				$list['pic'] = zanpian_img_url($read['news_pic']);
			}
			$list['time'] = time_format($read['news_addtime']);
			$list['addtime'] = date('Y-m-d H:i:s', $read['news_addtime']);
			$list['hits'] = $read['news_hits'];
			$list['inputer'] = $read['news_inputer'];
			if (!empty($read['news_next'])) {
				$list['next']['id'] = $read['news_next']['news_id'];
				$list['next']['title'] = $read['news_next']['news_name'];
			}
			if (!empty($read['news_prev'])) {
				$list['prev']['id'] = $read['news_prev']['news_id'];
				$list['prev']['title'] = $read['news_prev']['news_name'];
			}
			if (!empty($read['news_playname'])) {
				$list['playname'] = $read['news_playname'];
			}
			if (!empty($read['news_clarity'])) {
				$list['clarity'] = $read['news_clarity'];
			}
			if (!empty($read['news_playname'])) {
				$list['playtime'] = $read['news_playtime'];
			}
			if (!empty($read['news_playname'])) {
				$list['playurl'] = $read['news_playurl'];
			}
			if (!empty($read['news_vodid'])) {
				$list['vodid'] = $read['news_vodid'];
			}
			if (!empty($read['news_newsid'])) {
				$list['newsid'] = $read['news_newsid'];
			}
			$list['content'] = $read['news_content'];
			$vodlist = zanpian_mysql_topic('tid:' . $read['news_id'] . ';tsid: 2;sid: 1;limit: *;');
			if (!empty($vodlist)) {
				$list['vodlist'] = $this->format_vodlist($vodlist, 0, 0);
			} else {
				$list['vodlist'] = array();
			}
			return json(['data' => $list]);
		} else {
			return json(['data' => array()]);
		}
	}
	/**
	 * 单集剧情详情和详情列表
	 */
	public function storyread()
	{
		$Url = zanpiancms_param_url();
		$Url['p'] = input('p/d', '');
		$id = $Url['id'];
		$p = $Url['p'];
		$array_detail = $this->get_cache_story($Url);
		if (!empty($id)) {
			$this->set_hits($id, 4);
		}
		$partlist = zanpian_mysql_part('sid:' . $id . ';limit: *');
		$list = array();
		if ($array_detail) {
			$read = $array_detail['read'];
			if (!$p) {
				$list['vContent'] = strip_tags($read['vod_content']);
			}
			if ($p <= count($partlist)) {
				$data = $partlist[$p - 1];
				$list['id'] = $read['story_id'];
				$list['vid'] = $read['vod_id'];
				$list['vTitle'] = $read['vod_name'];
				$list['pic'] = zanpian_img_url($read['vod_pic']);
				if (is_numeric($read['vod_continu'])) {
					if ($read['vod_continu'] > 0) {
						$read['vod_continu'] = (int) $read['vod_continu'];
					} else {
						$read['vod_continu'] = '完结';
					}
				}
				$list['year'] = $read['vod_year'];
				$list['mcid'] = mcat_json($read['vod_mcid']);
				$list['status'] = $read['vod_continu'];
				$lastplayurl = play_url_end($read['vod_url'], $read['vod_play']);
				$list['sid'] = $lastplayurl[0];
				$list['pid'] = $lastplayurl[1];
				$list['lastname'] = $lastplayurl[2];
				$list['gold'] = $read['vod_gold'];
				$list['actor'] = $read['vod_actor'];
				$list['storyNum'] = $read['story_continu'];
				if ($data) {
					$list['name'] = $data['part_name'];
					$list['title'] = $data['part_title'];
					$list['content'] = $data['part_content'];
					$list['oid'] = $data['part_oid'];
					if ($data['part_oid'] == 1) {
						$list['next'] = $data['part_oid'] + 1;
					} elseif ($read['story_continu'] == $data['part_oid']) {
						$list['prev'] = $data['part_oid'] - 1;
					} else {
						$list['prev'] = $data['part_oid'] - 1;
						$list['next'] = $data['part_oid'] + 1;
					}
				}
				return json(['data' => $list]);
			} else {
				return json(['data' => array()]);
			}
		} else {
			return json(['data' => array()]);
		}
	}

	// 角色详情
	public function roleread()
	{
		$list = array();
		$param = zanpiancms_param_url();
		$array_detail = $this->get_cache_role($param);
		if ($array_detail) {
			$read = $array_detail['read'];
			$list['id'] = $read['role_id'];
			$list['cid'] = $read['role_cid'];
			$list['name'] = getlistname($read['role_cid'], 'list_name');
			$list['title'] = $read['role_name'];
			$list['pic'] = zanpian_img_url($read['role_pic']);
			$list['content'] = $read['role_content'];
			$list['starId'] = $read['star_id'];
			$list['starCid'] = $read['star_cid'];
			$list['starName'] = $read['star_name'];
			$list['starPic'] = $read['star_picurl'];
			$list['vid'] = $read['vod_id'];
			$list['vTitle'] = $read['vod_name'];
			return json(['data' => $list]);
		} else {
			return json(['data' => array()]);
		}
	}

	// 声优详情
	public function starread()
	{
		$list = array();
		$param = zanpiancms_param_url();
		$array_detail = $this->get_cache_star($param);
		if ($array_detail) {
			$read = $array_detail['read'];
			$show = $array_detail['show'];
			$list['id'] = $read['star_id'];
			$list['cid'] = $read['star_cid'];
			$list['name'] = getlistname($read['star_cid'], 'list_name');
			$list['title'] = $read['star_name'];
			$list['alias'] = $read['star_bm'];
			$list['enname'] = $read['star_wwm'];
			$list['pic'] = zanpian_img_url($read['star_pic']);
			$list['bigpic'] = zanpian_img_url($read['star_bigpic']);
			$list['sex'] = $read['star_xb'];
			$list['height'] = $read['star_sg'];
			$list['birthday'] = $read['star_cstime'];
			$list['school'] = $read['star_school'];
			$list['occupation'] = $read['star_zy'];
			$list['constellation'] = $read['star_xz'];
			$list['area'] = $read['star_area'];
			$list['nationality'] = $read['star_gj'];
			$list['from'] = $read['star_csd'];
			$list['content'] = $read['star_content'];
			$list['explist'] = $read['star_data'];
			$newslist = zanpian_mysql_topic('sid: 3;tsid: 2;did:' . $read['star_id'] . ';limit: 10;order:news_addtime desc;');
			$rolelist = zanpian_mysql_role('star:' . $read['star_name'] . ';limit: 10');
			$vodlist = zanpian_mysql_vod('actor: ' . $read['star_name'] . ';cid: ' . $show['id'] . ';limit: 10');
			$starlist = zanpian_mysql_star('star: ' . $read['star_name'] . ';guan: ' . $read['star_xi'] . 'limit: 10;order:star_hits desc');
			if ($newslist) {
				$list['newslist'] = $this->format_newslist($newslist);
			}
			if ($rolelist) {
				$list['rolelist'] = $this->format_rolelist($rolelist);
			}
			if ($vodlist) {
				$list['vodlist'] = $this->format_vodlist($vodlist);
			}
			if ($starlist) {
				$list['starlist'] = $this->format_star($starlist);
			}
			return json(['data' => $list]);
		}
		return json(['data' => array()]);
	}

	/**
	 * 获取评分和评论
	 */
	public function comment()
	{
		$param = zanpiancms_param_url();
		$lists = array();
		$model = $GLOBALS['config']['model'][$param['sid']];
		if (!empty($param['id']) && !empty($param['sid'])) {
			$data = zanpian_mysql_cm('vid: ' . $param['id'] . ';sid: ' . $param['sid'] . ';pid: 0;status: 1;page:true;p:' . $param['p'] . ';limit: ' . $GLOBALS['config']['user']['sys']['user_cmnum']);
			if ($data) {
				foreach ($data as $k => $v) {
					$sub = zanpian_mysql_cm('pid: ' . $v['cm_id'] . ';sid: ' . $v['cm_sid'] . ';order: cm_addtime desc');
					$floor = $data->total() - (($data->currentPage() - 1) * $data->listRows()) - $k;
					$list[$k]['id'] = $v['cm_id'];
					$list[$k]['sid'] = $v['cm_sid'];
					$list[$k]['up'] = $v['cm_up'];
					$list[$k]['down'] = $v['cm_down'];
					$list[$k]['time'] = zanpian_from_time($v['cm_addtime']);
					$list[$k]['uid'] = $v['cm_uid'];
					$list[$k]['username'] = $v['cm_username'];
					$list[$k]['content'] = get_emots(remove_xss(strip_tags($v['cm_content'])));
					$list[$k]['floor'] = $floor;
					$list[$k]['avatar'] = zanpian_avatar_url($v);
					if ($sub) {
						foreach ($sub as $key => $val) {
							$list[$k]['sub'][$key]['id'] = $val['cm_id'];
							$list[$k]['sub'][$key]['sid'] = $val['cm_sid'];
							$list[$k]['sub'][$key]['uid'] = $val['cm_uid'];
							$list[$k]['sub'][$key]['username'] = $val['cm_username'];
							$list[$k]['sub'][$key]['time'] = zanpian_from_time($val['cm_addtime']);
							$list[$k]['sub'][$key]['content'] = get_emots(remove_xss(strip_tags($val['cm_content'])));
							$list[$k]['sub'][$key]['up'] = $val['cm_up'];
							$list[$k]['sub'][$key]['down'] = $val['cm_down'];
							$list[$k]['sub'][$key]['avatar'] =  zanpian_avatar_url($val);
							if ($val['cm_tid']) {
								$list[$k]['sub'][$key]['replyname'] = get_user_info($val['cm_tuid'], 'user_id', 'user_nickname');
								$list[$k]['sub'][$key]['replyuid'] = get_user_info($val['cm_tuid'], 'user_id', 'user_id');
							}
							$list[$k]['sub'][$key]['floor'] = count($sub) - $key;
						}
					}
				}
				$lists['data']['list'] = $list;
				$lists['limit'] = (int) $data->listRows();
				$lists['current'] = $data->currentPage();
				$lists['count'] = $data->lastPage();
				$lists['total'] = $data->total();
			}
		}
		if (!empty($param['id']) && !empty($param['sid']) && !empty($model)) {
			$rs = model('gold');
			$start = array();
			$markdata = $rs->getGold($param['id'], $param['sid']);

			$value = $rs->getMarkValue($param['id'], $param['sid'], ip2long(request()->ip()));
			if ($value > 0) {
				$start['hadpingfen'] = 1;
				$start['mygold'] = $value;
			} else {
				$start['mygold'] = 0;
			}
			$start = array();
			$gold = db($model['name'])->where($model['name'] . '_id', $param['id'])->value($model['name'] . '_gold');
			if ($markdata != null) {
				$start['a'] = (int) $markdata['F5'];
				$start['b'] = (int) $markdata['F4'];
				$start['c'] = (int) $markdata['F3'];
				$start['d'] = (int) $markdata['F2'];
				$start['e'] = (int) $markdata['F1'];
				$rate = $rs->getPingfen($markdata);
				if (count($rate) > 0) {
					$start['pinfenb'] = $rate['R2'];
					$start['pinfen'] = $rate['R1'];
				} else {
					$start['a'] = 0;
					$start['b'] = 0;
					$start['c'] = 0;
					$start['d'] = 0;
					$start['e'] = 0;
					$start['pinfenb'] = $gold * 10;
					$start['pinfen'] = $gold;
				}
			}
			$lists['data']['gold'] = $start;
		}
		return json($lists);
	}



	//增加评分	
	public function addgold()
	{
		$id = input('id/d', 0);
		$sid = input('sid/d', 1);
		$value = input('val/d', 0);
		if (isset($id) && isset($value)) {
			if ($value == "1" || $value == "2" || $value == "3" || $value == "4" || $value == "5") {
				//查询一下
				$rs = model('gold');
				$count = $rs->where(array('gold_vid' => $id, 'gold_sid' => $sid, 'gold_ip' => ip2long(request()->ip())))->count();
				if ($count > 0) { //存在
					return json(['msg' => "已经评分,请务重复评分", 'code' => -1]);
				} else { //增加评分
					$mark = array();
					$mark['gold_vid'] = $id;
					$mark['gold_sid'] = $sid;
					$mark['gold_ip'] = ip2long(request()->ip());
					$mark['gold_addtime'] = time();
					$mark['F' . $value] = 1;
					if ($rs->insertGetId($mark) !== false) {
						$rate = $rs->getPingfen($id);
						if (count($rate) > 0) {
							db('vod')->where('vod_id', $id)->setField('vod_gold', $rate['R1']);
						}
						return json(['msg' => "提交评分成功", 'code' => 1]);
					} else {
						return json(['msg' => $rs->getError(), 'code' => -1]);
					}
				}
			}
		}
	}

	/**
	 * 送花，视频顶踩
	 */
	public function digg()
	{
		$param = zanpiancms_param_url();
		$name = htmlspecialchars(input('name/s', ''));
		$model = $GLOBALS['config']['model'][$param['sid']];
		if ($param['id'] && $param['type'] && $model['name']) {
			$data = $this->show($param['id'], $param['type'], $model['name'], $name);
		} else {
			$data = ['msg' => '参数错误', 'code' => -1];
		}
		return json($data);
	}

	private function show($id = '', $type = '', $model, $name)
	{
		$name = !empty($name) ? $name : '点评';
		if (in_array($type, array('up', 'down'))) {
			db($model)->where($model . '_id', $id)->setInc($model . '_' . $type);
			$data['cookietime'] = intval($GLOBALS['config']['user']['sys']['user_digg_time']);
			$data['cookiename'] = md5('digg-' . ip2long(request()->ip()) . '-' . intval($id) . '-' . intval($model));
			return array('data' => $data, 'msg' => $name . '成功', 'code' => 1);
		}
		return array('msg' => '参数错误', 'code' => -1);
	}

	// 格式化明星
	private function format_star($data)
	{
		if ($data) {
			foreach ($data as $key => $val) {
				$list[$key]['id'] = $val['star_id'];
				$list[$key]['title'] = $val['star_name'];
				$list[$key]['pic'] = zanpian_img_url($val['star_pic']);
			}
			return $list;
		} else {
			return false;
		}
	}

	// 格式化新闻列表
	private function f_newslist($data, $page) {
		$list = array();
		if (count($data)) {
			foreach ($data as $key => $val) {
				$list['data'][$key]['id'] = $val['news_id'];
				$list['data'][$key]['cid'] = $val['news_cid'];
				$list['data'][$key]['name'] = getlistname($val['news_cid'], 'list_name');
				$list['data'][$key]['title'] = $val['news_name'];
				$list['data'][$key]['addtime'] = date('Y-m-d H:i:s', $val['news_addtime']);
				if (!empty($val['news_pic'])) {
					$list['data'][$key]['pic'] = zanpian_img_url($val['news_pic']);
				}
				if ($val['news_jumpurl']) {
					$list['data'][$key]['jump'] = $val['news_jumpurl'];
				}
			}
			if ($page != '0') {
				$list['limit'] = (int) $data->listRows();
				$list['current'] = $data->currentPage();
				$list['count'] = $data->lastPage();
				$list['total'] = $data->total();
			}
		} else {
			if ($page != '0') {
				$list['limit'] = 10;
				$list['current'] = 1;
				$list['total'] = 0;
				$list['count'] = 0;
			}
			$list['data'] = array();
		}
		return json($list);
	}

	// 格式化视频列表
	private function vodlist($val, $order = '', $len = 0)
	{
		$list = array();
		$list['id'] = $val['vod_id'];
		$list['title'] = $val['vod_name'];
		if ($len == 100) {
			if ($order == 'hits' || $order == 'hits_day' || $order == 'hits_week' || $order == 'hits_month') {
				$list['gold'] = $val['vod_gold'];
			}
			if ($order == 'hits') {
				$list['hits'] = $val['vod_hits'];
			} elseif ($order == 'hits_day') {
				$list['hits'] = $val['vod_hits_day'];
			} elseif ($order == 'hits_week') {
				$list['hits'] = $val['vod_hits_week'];
			} elseif ($order == 'hits_month') {
				$list['hits'] = $val['vod_hits_month'];
			} elseif ($order == 'addtime') {
				$list['listName'] = getlistname($val['vod_cid'], 'list_name');
				$list['listId'] = $val['vod_cid'];
				$list['mcid'] = mcat_json($val['vod_mcid']);
				$list['time'] = date('Y-m-d H:i:s', $val['vod_addtime']);
				$list['isDate'] = date('Y-m-d') == date('Y-m-d', $val['vod_addtime']) ? 1 : 0;
				if($val['vod_url']) {
					$lastplayurl = play_url_end($val['vod_url'], $val['vod_play']);
					$list['sid'] = $lastplayurl[0];
					$list['pid'] = $lastplayurl[1];
					$list['lastname'] = $lastplayurl[2];
				}
			}
		} else {
			$list['gold'] = $val['vod_gold'];
			$list['weekday'] = (int) $val['vod_weekday'];
			$list['year'] = $val['vod_year'];
			$list['area'] = $val['vod_area'];
			$list['pic'] = zanpian_img_url($val['vod_pic']);
			$list['isDate'] = date('Y-m-d') == date('Y-m-d', $val['vod_addtime']) ? 1 : 0;
			if ($val['vod_bigpic']) {
				$list['smallPic'] = zanpian_img_url($val['vod_bigpic']);
			}
			if (is_numeric($val['vod_continu'])) {
				if ($val['vod_continu'] > 0) {
					$val['vod_continu'] = (int) $val['vod_continu'];
				} else {
					$val['vod_continu'] = '完结';
				}
			}
			$list['year'] = $val['vod_year'];
			$list['mcid'] = mcat_json($val['vod_mcid']);
			$list['status'] = $val['vod_continu'];
			$list['weekday'] = (int) $val['vod_weekday'];
			if($val['vod_url']) {
				$lastplayurl = play_url_end($val['vod_url'], $val['vod_play']);
				$list['sid'] = $lastplayurl[0];
				$list['pid'] = $lastplayurl[1];
				$list['lastname'] = $lastplayurl[2];
			}
		}
		return $list;
	}

	private function format_vodlist($data, $order = '', $week = '')
	{
		$k = 0;
		$list = array();
		foreach ($data as $key => $val) {
			if ($week) {
				if ($val['vod_prty'] == 4) {
					$list[$k] = $this->vodlist($val);
					$k = $k + 1;
				}
			} else {
				$list[$key] = $this->vodlist($val, $order, count($data));
			}
		}
		return $list;
	}

	/**
	 * 格式化输出数据
	 */
	private function format_data($data, $page = '0', $week = '', $order = '')
	{
		if ($data) {
			$list['data'] = $this->format_vodlist($data, $order, $week);
			if ($page != '0') {
				$list['limit'] = (int) $data->listRows();
				$list['current'] = $data->currentPage();
				$list['count'] = $data->lastPage();
				$list['total'] = $data->total();
			}
		} else {
			if ($page != '0') {
				$list['limit'] = 10;
				$list['current'] = 1;
				$list['total'] = 0;
				$list['count'] = 0;
			}
			$list['data'] = array();
		}
		return json($list);
	}

	/**
	 * 格式化角色列表
	 */
	private function format_rolelist($data)
	{
		$list = array();
		if ($data) {
			foreach ($data as $key => $val) {
				$list[$key]['roleId'] = $val['role_id'];
				$list[$key]['starId'] = $val['star_id'];
				$list[$key]['roleName'] = $val['role_name'];
				$list[$key]['starName'] = $val['star_name'];
				$list[$key]['rolePic'] = zanpian_img_url($val['role_pic']);
				$list[$key]['starPic'] = zanpian_img_url($val['star_pic']);
			}
			return $list;
		} else {
			return false;
		}
	}

	// 格式化新闻
	private function format_newslist($data, $isText = '')
	{
		$list = array();
		if ($data) {
			foreach ($data as $key => $val) {
				$list[$key]['id'] = $val['news_id'];
				$list[$key]['title'] = $val['news_name'];
				if ($isText) {
					$list[$key]['addtime'] = date('Y-m-d', $val['news_addtime']);
					$list[$key]['playname'] = $val['news_playname'];
					$list[$key]['clarity'] = $val['news_clarity'];
					$list[$key]['playtime'] = $val['news_playtime'];
				} else {
					$list[$key]['cid'] = $val['news_cid'];
					$list[$key]['name'] = getlistname($val['news_cid'], 'list_name');
					$list[$key]['pic'] = zanpian_img_url($val['news_pic']);
					$list[$key]['jump'] = $val['news_jumpurl'];
				}
			}
			return $list;
		} else {
			return false;
		}
	}

	/**
	 * 剧情详情页列表
	 */
	private function format_part($data)
	{
		$list = array();
		if ($data) {
			foreach ($data as $i => $val) {
				$list[$i]['pid'] = $val['part_id'];
				$list[$i]['name'] = $val['part_name'];
				$list[$i]['title'] = $val['part_title'];
				$list[$i]['content'] = $val['part_content'];
			}
			return $list;
		} else {
			return false;
		}
	}

	//处理各模块的人气值刷新
	private function modelhits_insert($sid, $array)
	{
		//初始化值
		$hits[$sid . '_hits'] = $array[$sid . '_hits'];
		$hits[$sid . '_hits_month'] = $array[$sid . '_hits_month'];
		$hits[$sid . '_hits_week'] = $array[$sid . '_hits_week'];
		$hits[$sid . '_hits_day'] = $array[$sid . '_hits_day'];
		$new = getdate();
		$old = getdate($array[$sid . '_hits_lasttime']);
		//月
		if ($new['year'] == $old['year'] && $new['mon'] == $old['mon']) {
			$hits[$sid . '_hits_month']++;
		} else {
			$hits[$sid . '_hits_month'] = 1;
		}
		//周
		$weekStart = mktime(0, 0, 0, $new["mon"], $new["mday"], $new["year"]) - ($new["wday"] * 86400); //本周开始时间,本周日0点0
		$weekEnd = mktime(23, 59, 59, $new["mon"], $new["mday"], $new["year"]) + ((6 - $new["wday"]) * 86400); //本周结束时间,本周六12点59
		if ($array[$sid . '_hits_lasttime'] >= $weekStart && $array[$sid . '_hits_lasttime'] <= $weekEnd) {
			$hits[$sid . '_hits_week']++;
		} else {
			$hits[$sid . '_hits_week'] = 1;
		}
		//日
		if ($new['year'] == $old['year'] && $new['mon'] == $old['mon'] && $new['mday'] == $old['mday']) {
			$hits[$sid . '_hits_day']++;
		} else {
			$hits[$sid . '_hits_day'] = 1;
		}
		//更新数据库
		$hits[$sid . '_id'] = $array[$sid . '_id'];
		$hits[$sid . '_hits'] = $hits[$sid . '_hits'] + 1;
		$hits[$sid . '_hits_lasttime'] = time();
		//print_r($hits) ;
		db(ucfirst($sid))->update($hits, [$sid . '_id' => $hits[$sid . '_id']]);
		return $hits;
	}

	private function set_hits($id, $sid = 1)
	{
		$mode = $GLOBALS['config']['model'][$sid];
		if ($mode['name']) {
			$where[$mode['name'] . '_id'] = $id;
			$array = db(ucfirst($mode['name']))->field($mode['name'] . '_id,' . $mode['name'] . '_hits,' . $mode['name'] . '_hits_month,' . $mode['name'] . '_hits_week,' . $mode['name'] . '_hits_day,' . $mode['name'] . '_addtime,' . $mode['name'] . '_hits_lasttime')->where($where)->find();
			return $this->modelhits_insert($mode['name'], $array);
		} else {
			return false;
		}
	}


	// 从声优数据库获取数据
	private function get_cache_star($param)
	{
		if (empty($param['id']) && empty($param['pinyin'])) {
			return false;
		}
		//优先读取缓存数据
		if ($GLOBALS['config']['cache']['data_cache_star']) {
			$array_detail = Cache::get('data_cache_star_' . $param['id'] . $param['pinyin']);
			if ($array_detail) {
				return $array_detail;
			}
		}
		//未中缓存则从数据库读取
		$where = array();
		if (!empty($param['id'])) {
			$where['star_id'] = $param['id'];
		}
		if (!empty($param['pinyin'])) {
			$where['star_letters'] = $param['pinyin'];
		}
		$where['star_status'] = array('eq', 1);
		$data = db('star')->where($where)->find();
		if (!empty($data)) {
			//解析标签
			$array_detail = $this->Lable_Star_Read($data, 3);
			if ($GLOBALS['config']['cache']['data_cache_star']) {
				Cache::tag('model_star')->set('data_cache_star_' . $param['id'] . $param['pinyin'], $array_detail, intval($GLOBALS['config']['cache']['data_cache_star']));
			}
			return $array_detail;
		}
		return false;
	}

	// 从角色数据库获取数据
	private function get_cache_role($param)
	{
		if (empty($param['id'])) {
			return false;
		}
		//优先读取缓存数据
		if ($GLOBALS['config']['cache']['data_cache_role']) {
			$array_detail = Cache::get('data_cache_role_' . $param['id']);
			if ($array_detail) {
				return $array_detail;
			}
		}
		//未中缓存则从数据库读取
		$where = array();
		if (!empty($param['id'])) {
			$where['role_id'] = $param['id'];
		}
		$where['role_status'] = array('eq', 1);
		$data = db('role')->alias('role')->join('actor actor', 'actor.actor_vid =role.role_vid', 'LEFT')->join('star star', 'star.star_name =role.role_star', 'LEFT')->join('story story', 'story.story_vid =role.role_vid', 'LEFT')->join('vod vod', 'vod.vod_id =role.role_vid', 'LEFT')->where($where)->find();
		if (!empty($data)) {
			//解析标签
			$array_detail = $this->Lable_Vod_Read($data, 5);
			if ($GLOBALS['config']['cache']['data_cache_role']) {
				Cache::tag('data_role')->set('data_cache_role_' . $param['id'], $array_detail, intval($GLOBALS['config']['cache']['data_cache_role']));
			}
			return $array_detail;
		}
		return false;
	}

	// 新闻从数据库获取数据
	private function get_cache_news($param)
	{
		if (!$param['id']) {
			return false;
		}
		//优先读取缓存数据
		if ($GLOBALS['config']['cache']['data_cache_news']) {
			$array_detail = Cache::get('data_cache_news_' . $param['id']);
			if ($array_detail) {
				return $array_detail;
			}
		}
		//未中缓存则从数据库读取
		$where = array();
		$where['news_id'] = $param['id'];
		$where['news_status'] = array('eq', 1);
		$data = db('news')->where($where)->find();
		if (!empty($data)) {
			//解析标签
			$array_detail = $this->Lable_News_Read($data, $param);
			if ($GLOBALS['config']['cache']['data_cache_news']) {
				Cache::tag('data_news')->set('data_cache_news_' . $param['id'], $array_detail, intval($GLOBALS['config']['cache']['data_cache_news']));
			}
			return $array_detail;
		}
		return false;
	}

	// 从剧情数据库获取数据
	private function get_cache_story($param)
	{
		if (empty($param['id']) && empty($param['pinyin']) && empty($param['vid'])) {
			return false;
		}

		//优先读取缓存数据
		if ($GLOBALS['config']['cache']['data_cache_story']) {
			$array_detail = Cache::get('data_cache_story_' . $param['id'] . $param['vid'] . $param['pinyin']);
			if ($array_detail) {
				return $array_detail;
			}
		}
		//未中缓存则从数据库读取
		$where = array();
		if (!empty($param['id'])) {
			$where['story_id'] = $param['id'];
		}
		if (!empty($param['vid'])) {
			$where['story_vid'] = $param['vid'];
		}
		if (!empty($param['pinyin'])) {
			$where['vod_letters'] = $param['pinyin'];
		}
		$where['story_status'] = array('eq', 1);
		$data = db('story')->alias('story')->join('vod vod', 'vod.vod_id =story.story_vid', 'LEFT')->join('actor actor', 'actor.actor_vid =story.story_vid', 'LEFT')->where($where)->find();
		if (!empty($data)) {
			//解析标签
			$array_detail = $this->Lable_Read($data, 4);
			if ($GLOBALS['config']['cache']['data_cache_story']) {
				Cache::tag('data_story')->set('data_cache_story_' . $param['id'] . $param['vid'] . $param['pinyin'], $array_detail, intval($GLOBALS['config']['cache']['data_cache_story']));
			}
			return $array_detail;
		}
		return false;
	}

	//从数据库获取数据
	private function get_cache_detail($param)
	{
		if (empty($param['id']) && empty($param['pinyin'])) {
			return false;
		}
		//优先读取缓存数据
		if ($GLOBALS['config']['cache']['data_cache_vod']) {
			$array_detail = Cache::get('data_cache_vod_' . $param['id'] . $param['pinyin']);
			if ($array_detail) {
				return $array_detail;
			}
		}
		//未中缓存则从数据库读取
		$where = array();
		if (!empty($param['id'])) {
			$where['vod_id'] = $param['id'];
		}
		if (!empty($param['pinyin'])) {
			$where['vod_letters'] = $param['pinyin'];
		}
		$where['vod_status'] = array('eq', 1);
		$data = db('vod')->alias('vod')->join('actor actor', 'actor.actor_vid =vod.vod_id', 'LEFT')->join('story story', 'story.story_vid =vod.vod_id', 'LEFT')->where($where)->find();
		if (!empty($data)) {
			//解析标签
			$array_detail = $this->Lable_Vod_Read($data, 1);
			if ($GLOBALS['config']['cache']['data_cache_vod']) {
				Cache::tag('data_vod')->set('data_cache_vod_' . $param['id'] . $param['pinyin'], $array_detail, intval($GLOBALS['config']['cache']['data_cache_vod']));
			}
			return $array_detail;
		}
		return false;
	}
}
